package com.hzh.cusviewdemo.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hzh.cusviewdemo.Bean.TypeData;
import com.hzh.cusviewdemo.R;

import java.util.List;

/**
 * 右侧数据列表适配器
 */
public class RightListAdapter extends RecyclerView.Adapter<RightListAdapter.MyHolder> {

    private List<TypeData> dataList;
    private Context context;

    private int nowPosition;
    private OnTypeListener mListener;

    public interface OnTypeListener {
        void onClickType(TypeData data);
    }

    public void setOnTypeListener(OnTypeListener listener) {
        mListener = listener;
    }

    public RightListAdapter(List<TypeData> dataList, Context context) {
        this.dataList = dataList;
        this.context = context;
    }

    @NonNull
    @Override
    public RightListAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_choose_right, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RightListAdapter.MyHolder holder, int position) {
        holder.icr_type.setText(dataList.get(position).getTitle());
        ClassAdapter classAdapter = new ClassAdapter(dataList.get(position).getChild());
        holder.icr_class_list.setLayoutManager(new LinearLayoutManager(context));
        holder.icr_class_list.setAdapter(classAdapter);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    static class MyHolder extends RecyclerView.ViewHolder {

        private TextView icr_type;
        private RecyclerView icr_class_list;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            icr_type = itemView.findViewById(R.id.icr_type);
            icr_class_list = itemView.findViewById(R.id.icr_class_list);
        }
    }


}
